How to list all tables in a schema having specific column in oracle SQL?
How to list all tables in a schema having specific column in oracle SQL?
572
17-Jul-2023
Updated on 18-Jul-2023
Aryan Kumar
18-Jul-2023Sure, here is how you can list all tables in a schema having specific column in Oracle SQL:
SQL
This query will first select all tables from the
user_tablesview. Theuser_tablesview is a data dictionary view that contains information about all of the tables in the schema that the user is currently logged in to.The next part of the query uses the
EXISTSclause to check if each table in theuser_tablesview has the specified column. TheEXISTSclause takes a subquery as its argument. The subquery in this case selects all columns from theuser_tab_colsview where the table name is equal to the table name in theuser_tablesview and the column name is equal to the specified column.If the subquery returns any rows, then the
EXISTSclause will returnTRUE. This means that the table in theuser_tablesview has the specified column.The final part of the query selects the
table_namecolumn from theuser_tablesview for all tables that have the specified column.To run this query, you will need to connect to the Oracle database using a tool like SQLPlus. Once you are connected, you can run the query by typing it into the SQLPlus prompt.
For example, to run the query above, you would type the following into the SQL*Plus prompt:
SQL
This would return a list of all tables in the schema that the user is currently logged in to that have the specified column.